<template>
  <div class="login-container">
    <div class="login-header">
      <div class="logo">
        <span class="logo-text">logo</span>
      </div>
      <h1 class="system-title">企业档案管理系统</h1>
    </div>
    <el-form :model="form" ref="form" class="login-form" @submit.native.prevent="onSubmit">
      <h2 class="title">登录</h2>
      <el-form-item prop="username">
        <el-input v-model="form.username" placeholder="请输入用户名" prefix-icon="el-icon-user" />
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" type="password" placeholder="请输入密码" prefix-icon="el-icon-lock" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit" style="width:100%">登录</el-button>
        <el-link type="primary" @click="$router.push('/register')">没有账号？去注册</el-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import service from '@/utils/request';
export default {
  name: 'Login',
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    async onSubmit() {
      try {
        const res = await service.post('/user/login', null, {
          params: this.form
        });
        if (res.data.code === 200) {
          localStorage.setItem('token', res.data.data.token);
          localStorage.setItem('user', JSON.stringify(res.data.data.user));
          this.$router.push('/');
          this.$message.success(res.data.message);
        } else {
          this.$message.error(res.data.message);
        }
      } catch (e) {
        this.$message.error('登录失败');
      }
    }
  }
}
</script>

<style scoped>
.login-container {
  width: 400px;
  margin: 80px auto;
  padding: 40px 30px 30px 30px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  margin-bottom: 15px;
}

.logo-text {
  display: inline-block;
  font-size: 48px;
  font-weight: 400;
  color: #4A90E2;
  font-family: 'Brush Script MT', 'Lucida Handwriting', 'Apple Chancery', cursive;
  font-style: normal;
  text-decoration: none;
  transform: rotate(-2deg);
  letter-spacing: 1px;
}

.system-title {
  font-size: 18px;
  color: #666;
  font-weight: normal;
  margin: 0;
  letter-spacing: 2px;
}

.title {
  text-align: center;
  margin-bottom: 30px;
  color: #303133;
  font-weight: 500;
}

.login-form {
  margin-top: 20px;
}

.login-form .el-form-item {
  margin-bottom: 25px;
}

.login-form .el-input {
  height: 45px;
}

.login-form .el-input__inner {
  height: 45px;
  line-height: 45px;
  border-radius: 6px;
  border: 1px solid #dcdfe6;
  transition: border-color 0.2s;
}

.login-form .el-input__inner:focus {
  border-color: #409EFF;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

.login-form .el-button {
  height: 45px;
  border-radius: 6px;
  font-size: 16px;
  margin-bottom: 15px;
}

.login-form .el-link {
  display: block;
  text-align: center;
  margin-top: 10px;
}
</style> 